package com.xdhl.fu.fi.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.xdhl.fu.common.core.web.controller.BaseController;
import com.xdhl.fu.common.core.web.domain.AjaxResult;
import com.xdhl.fu.common.core.web.page.TableDataInfo;
import com.xdhl.fu.common.log.annotation.Log;
import com.xdhl.fu.common.log.enums.BusinessType;
import com.xdhl.fu.common.security.annotation.RequiresPermissions;
import com.xdhl.fu.fi.service.IFlightStockService;
import com.xdhl.fu.flight.info.api.domain.FlightStock;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Arrays;
import java.util.List;

/**
 * 飞机航班库存信息Controller
 *
 * @author 朱力维
 * @date 2022-06-24
 */
@RestController
@RequestMapping("/stock")
public class FlightStockController extends BaseController {
    @Resource
    private IFlightStockService flightStockService;

    /**
     * 查询飞机航班库存信息
     * 列表
     */
    @RequiresPermissions("flight:stock:list")
    @GetMapping("/list")
    public TableDataInfo list(FlightStock flightStock) {
        startPage();
        LambdaQueryWrapper<FlightStock> wrapper = new LambdaQueryWrapper<>();
        List<FlightStock> list = flightStockService.list(wrapper);
        return getDataTable(list);
    }

    /**
     * 获取飞机航班库存信息
     * 详细信息
     */
    @RequiresPermissions("flight:stock:query")
    @GetMapping(value = "/{dataId}")
    public AjaxResult getInfo(@PathVariable("dataId") String dataId) {
        return AjaxResult.success(flightStockService.getById(dataId));
    }

    /**
     * 新增飞机航班库存信息
     */
    @RequiresPermissions("flight:stock:add")
    @Log(title = "飞机航班库存信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FlightStock flightStock) {
        return toAjax(flightStockService.save(flightStock));
    }

    /**
     * 修改飞机航班库存信息
     */
    @RequiresPermissions("flight:stock:edit")
    @Log(title = "飞机航班库存信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FlightStock flightStock) {
        return toAjax(flightStockService.updateById(flightStock));
    }

    /**
     * 删除飞机航班库存信息
     */
    @RequiresPermissions("flight:stock:remove")
    @Log(title = "飞机航班库存信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{dataIds}")
    public AjaxResult remove(@PathVariable String[] dataIds) {
        return toAjax(flightStockService.removeByIds(Arrays.asList(dataIds)));
    }
}